package com.itheima.controller;

import com.itheima.bean.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpSession;


@Controller
@RequestMapping("/user")
@ResponseBody
public class UserController{

    @Autowired
    private UserService userService;


    @RequestMapping("/login")
    protected boolean login(User user, HttpSession session){

        User existUser = userService.login(user);

        //3 判断如果user!=null,说明登录成功，将user保存到session
        if(existUser!=null){

            session.setAttribute("user",existUser);

        }
        return existUser != null;
    }


}
